Fix worktree removal timing out on large install trees#3902
Fix worktree removal timing out on large install trees#3902jakeleventhal wants to merge 5 commits into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Needs human review 1 blocking correctness issue found. This PR introduces new filesystem deletion and retry logic for worktree removal. Two unresolved review comments identify potential bugs: incorrect parsing of paths with special characters, and bypassing worktree locks which could cause data loss. These substantive issues warrant human review. You can customize Macroscope's approvability policy. Learn more. |
Force-remove deletes the working tree via the filesystem first so git only cleans registration metadata, instead of timing out while walking multi-GB node_modules. Co-authored-by: Cursor <cursoragent@cursor.com>
Only wipe the directory after confirming the path is a linked entry from `git worktree list`, so mistyped or non-worktree paths are left intact. Co-authored-by: Cursor <cursoragent@cursor.com>
If listing times out or fails, skip the filesystem pre-delete and still run git worktree remove instead of aborting the whole operation. Co-authored-by: Cursor <cursoragent@cursor.com>
35a62d9 to
4ce5dfa
Compare
| return splitNullSeparatedPaths(result.stdout, result.stdoutTruncated); | ||
| } | ||
|
|
||
| export function parsePorcelainWorktreePaths(stdout: string): string[] { |
There was a problem hiding this comment.
🟡 Medium vcs/GitVcsDriverCore.ts:239
parsePorcelainWorktreePaths splits the porcelain output on \n and trims each path, so worktree paths containing a newline or trailing whitespace are parsed incorrectly. For such a worktree, the registration check fails and the filesystem pre-delete is skipped, causing removal to fall back to the slow git worktree remove path this PR is meant to avoid. Git documents that worktree list --porcelain -z must be used to correctly parse paths containing newlines. Consider switching to the -z (NUL-delimited) format and splitting on \0 instead.
🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/server/src/vcs/GitVcsDriverCore.ts around line 239:
`parsePorcelainWorktreePaths` splits the porcelain output on `\n` and trims each path, so worktree paths containing a newline or trailing whitespace are parsed incorrectly. For such a worktree, the registration check fails and the filesystem pre-delete is skipped, causing removal to fall back to the slow `git worktree remove` path this PR is meant to avoid. Git documents that `worktree list --porcelain -z` must be used to correctly parse paths containing newlines. Consider switching to the `-z` (NUL-delimited) format and splitting on `\0` instead.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4ce5dfa. Configure here.
| onSome: () => Effect.void, | ||
| }), | ||
| ), | ||
| ); |
There was a problem hiding this comment.
Force delete bypasses worktree locks
Medium Severity
The force path recursively deletes a linked worktree via the filesystem after only checking porcelain path membership. It never inspects a porcelain locked record, and the later git worktree remove still passes only a single --force. Git refuses locked worktrees unless forced twice, so a locked tree can be wiped on disk before git rejects the removal, leaving data gone and cleanup failing.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 4ce5dfa. Configure here.


Summary
Solves #3593
git worktree removetimeout on multi-GB trees with setup artifacts likenode_modules.Test plan
Git command timed out/ worktree removal failure~/.t3/worktrees/...andgit worktree listno longer lists itvp testinapps/serverforsrc/vcs/GitVcsDriverCore.test.tsMade with Cursor
Note
Fix worktree removal timing out on large install trees by pre-deleting directories
removeWorktree(force)inGitVcsDriverCore.tsnow pre-deletes the worktree directory viafileSystem.removebefore callinggit worktree remove, avoiding git's own slow filesystem traversal on large trees.git worktree list --porcelain), preventing accidental deletion of unregistered directories.Busy,WouldBlock,Unknown) are retried up to 50 times with 100ms spacing; the overall pre-delete step times out after 5 minutes, and the final git step uses a 60s timeout.parsePorcelainWorktreePathsto extract worktree paths from porcelain output, and new tests covering retry behavior, safety checks on non-registered paths, and filesystem cleanup.Macroscope summarized 2c45b97.